package com.example.demo.controller;

import com.example.demo.pojo.PublicFields;
import com.example.demo.pojo.Result;
import com.example.demo.pojo.dto.InboundDTO;
import com.example.demo.pojo.query.InboundQuery;
import com.example.demo.pojo.vo.InboundVO;
import com.example.demo.pojo.vo.PageVO;
import com.example.demo.service.imply.IInboundServiceImply;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/inbound")
@Api(tags = "入库相关接口")
@RequiredArgsConstructor
@CrossOrigin(origins = {"http://localhost:8080"}, allowCredentials = "true")
public class InboundController {
    private final IInboundServiceImply inboundService;
    @ApiOperation("入库物资")
    @PostMapping("/add")
    public Result addComponent(@RequestBody InboundDTO inboundDTO) {

        inboundService.addStorage(inboundDTO, PublicFields.newInstance());

        return Result.success("新增成功");
    }

    @ApiOperation("批量清除入库表数据")
    @PostMapping("/delete")
    public Result deleteDevice(@RequestBody List<Long> ids){

        inboundService.deleteInbound(ids);

        return Result.success("删除成功");
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public Result<PageVO<InboundVO>> page(InboundQuery inboundQuery){

        return Result.success(inboundService.queryComponentPage(inboundQuery));
    }
}
